<?php

class Activity extends MY_Pc_Api_Controller
{
    protected $_page_size;
    function __construct(){
        parent::__construct();
        $this->_page_size = $this->config->item('page_size','default');
    }

    /**
     * 获取活动列表  GET
     *
     * @return json
     */
    function gets(){
        $page = $this->input->get('page');
        $page = $page>0 ? $page : 1;
        $status = $this->input->get('status');
        $status = empty($status)?'recommend':$status;
        $field  = $this->input->get('field');
        $field  = empty($field)?'id':$field;
        $sort   = $this->input->get('sort')=='asc'?'asc':'desc';
        $condition = array(
            'is_del'    =>  0,
            'is_sold'   =>  1,
        );
        $options = array(
            'limit' =>array(
                $this->_page_size,
                ($page-1)*$this->_page_size
            ),
            'order'=>
                array($field.' '.$sort)
        );

        if($status=='recommend'){
            $this->config->load('data/recommend');
            $this->json_response(true,$this->config->item('index')['recommend_activity']);
        }
        if($status=='history'){
            $condition['is_sold'] = 0;
        }

        $this->load->model('activities/Activities_model');
        $activity = $this->Activities_model->get_activities(
            $condition,
            array('title','cover','intro','content','price','special_info','created','places','sold'),
            $options
        );
        if(!$activity){
            $this->json_response(false);
        }
        $this->json_response(true,$activity);
    }

    /**
     * 获取活动信息
     */
    function get(){
        $activity_id = $this->input->get('activity_id ');
        $condition = array('is_del'=>0);
        if($activity_id<0){
            $this->json_response(false);
        }
        $this->load->model('activities/Activities_model');
        $this->load->model('place/Place_model');
        $this->load->model('lecturer/Lecturer_model');
        $condition['id'] = $activity_id;
        $activity = $this->Activities_model->getOne($condition);
        $activity['place'] = $this->Place_model->getOne(array('id'=>$activity['place_id']));
        $activity['lecturer'] = $this->Lecturer_model->getOne(array('id'=>$activity['lecturer_id']));
        if(!$activity)
            $this->json_response(false);
         $this->json_response(true,$activity);
    }
    /**
     *  获取推荐活动（内容推荐）
     */
    function get_recommend(){
        $this->config->load('data/recommend');
        $this->json_response(true,$this->config->item('content')['recommend_activity']);
    }

}